package function;

import bean.UserBehavior;
import util.DBConnectionUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UserBehaviorDao {
    public void insertUserBehavior(UserBehavior behavior) {
        String sql = "INSERT INTO user_behavior (user_id, behavior_type, item_count, payment_amount, event_time) VALUES (?,?,?,?,?)";
        try (Connection conn = DBConnectionUtil.getConnection();
             PreparedStatement pstmt = conn.prepareStatement(sql)) {
            pstmt.setString(1, behavior.getUserId());
            pstmt.setString(2, behavior.getBehaviorType());
            pstmt.setInt(3, behavior.getItemCount());
            pstmt.setDouble(4, behavior.getPaymentAmount());
            pstmt.setTimestamp(5, behavior.getEventTime());
            pstmt.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}